﻿/// <reference path="BaseComplexControl.js" />
/// <reference path="FieldBinding.js" />

var $BaseComplexValueControl = TA.Turbo.Controls.BaseComplexValueControl = function BaseComplexValueControl(clientId)
{
	if (Function.IsInherit(arguments)) return;

	this.BaseComplexControl(clientId);
}
$BaseComplexValueControl.Inherit($BaseComplexControl);
var ____a;
if (____a)
{
	$BaseComplexValueControl.prototype = new $BaseComplexControl();
	$BaseComplexValueControl.prototype.BaseComplexControl = new $BaseComplexControl();
}

$PropertyDefinition.Define($BaseComplexValueControl, "Data", "D", new $FieldBinding(), {
	Serializable: $FieldBinding
});

$BaseComplexValueControl.DefineEvent(new $ServerEvent("ValueChanged"));

$BaseComplexValueControl.prototype._objectValue = null;
//$BaseComplexValueControl.prototype._modified = false;


// INSTANCE
$BaseComplexValueControl.prototype.get_Value = function get_Value()
{
	return this._objectValue;
}
$BaseComplexValueControl.prototype.set_Value = function set_Value(v)
{
	this._objectValue = v;
	this._OnValueSet();
	this._OnValueChanged();
}
$BaseComplexValueControl.prototype._Deserialize = function _Deserialize(json)
{
	return eval("(" + json + ")");
}
$BaseComplexValueControl.prototype.get_SerializedValue = function get_SerializedValue()
{
	//	if (this._modified)
	//	{
	var sb = new StringBuilder();
	var jw = new JsonWriter(sb);
	jw.Value(this.get_Value());
	return sb.toString();
	//		this.get_Control().value = sb.toString();
	//		this._modified = false;
	//	}
	//	return this.get_Control().value;
}
$BaseComplexValueControl.prototype.set_SerializedValue = function set_SerializedValue(value)
{
	//	if (this.get_SerializedValue() != value)
	//	{
	//		this._control.value = value;
	this.set_Value(this._Deserialize(value));
	//	}
}
$BaseComplexValueControl.prototype.Load = function Load()
{
	this.BaseComplexControl.Load.call(this);

	//	if (this.get_Control().value == null)
	//	{
	//		this.get_Control().value = this.get_Control().getAttribute("value");
	//		this.get_Control().removeAttribute("value");
	//	}
	//	this._objectValue = this._Deserialize(this.get_Control().value);

	this._modified = false;
}




// INTERNAL
$BaseComplexValueControl.prototype._OnValueSet = function _OnValueSet()
{
}
$BaseComplexValueControl.prototype._OnValueChanged = function OnValueChanged()
{
	this._modified = true;
	this.RaiseEvent("ValueChanged", null);
}
